/*
package com.bestom.t9.control;

import android.content.Intent;
import android.util.Log;
import android.widget.TextView;
import android.widget.Toast;

import com.bestom.t9.service.SerialPortService;
import com.bestom.t9.utils.BinaryDataConversion;
import com.bestom.t9mod.commons.utils.DataTurn;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import android_serialport_api.SerialPort;

*/
/**
 * @author ..
 *//*

public class PowerControl {



    private DataTurn mDataTurn;

    public PowerControl(){

        mDataTurn = new DataTurn();
    }

    private BinaryDataConversion mBinaryDataConversion = new BinaryDataConversion();
    private int bit;
    private int state;
    public void sendInstruct(int bit, int state){

        this.bit = bit;
        this.state = state;

        // 1、读取当前电源状态
        // 2、16数据转换-->2进制数据
        // 3、状态位改变
        // 4、2数据转换-->16进制数据

        readPowerState();
    }

    private void readPowerState() {
        writeHexToBoard();

    }
    private boolean flagWrite = true;
    private short data;
    private void writeHexToBoard() {

        Log.d("PowerControl","writeHexToBoard");

        short regData;
        if (state == 1){
            regData = mBinaryDataConversion.computRegData(data, bit);
        }else{
            regData = mBinaryDataConversion.computRegOpenData(data,bit);
        }
        String hexString = Integer.toHexString(regData);
        String hex= "55 3a 05 02 " + hexString;


        String result = mBinaryDataConversion.makeChecksum(hex);

        // "553a0502 + hexString + result" 为控制电源状态的指令
        byte[] bytes = mDataTurn.HexToByteArr("553a0502" + hexString + result);

        // 写入数据
        try {
            mOutputStream.write(bytes);
            mOutputStream.flush();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }



    private ReadThread readThread;
    private void readReturnResult(){
        // 开启子线程，不断读取返回结果
        if (readThread == null)
            readThread = new ReadThread();
        readThread.start();
    }

    private class ReadThread extends Thread {
        @Override
        public void run() {
            super.run();

            // 写入板子，获取板子返回数据时 flag 为 true, 改写电量之后 flag 为 false
            boolean flagRead = true;
            while (flagRead) {
                try {
                    if (mInputStream == null)
                        return;

                    byte[] buffer = new byte[80];
                    int size = mInputStream.read(buffer);

                    if (size > 0) {
                        byte[] readBytes = new byte[size];
                        System.arraycopy(buffer, 0, readBytes, 0, size);
                        // 将 byte字节数组获取有关位置转换为 二进制
                        Integer integer = get2Byte(readBytes);
                        if (integer != -1){
                            flagRead = false;
                            flagWrite = false;
                            data = integer.shortValue();
                        }

                    }
                } catch (Throwable e) {
                    e.printStackTrace();
                }
            }
        }
    }

    private Integer get2Byte(byte[] readBytes){

        String hex = mDataTurn.ByteArrToHex(readBytes);
        int hexLength = hex.length();
        String dataLength = "0606";
        boolean flag = hex.contains(dataLength) && (hexLength == 10 || hexLength == 12 || hexLength == 14);
        if (flag){
            // 截取电量状态字符串
            String electricString = hex.substring(hexLength - 4, hexLength - 2);
            // 16进制数转化为10进制数
            Integer electricData = Integer.valueOf(electricString,16);
            return electricData;
        }
        return -1;
    }



}
*/
